<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="/WEB-INF/tld/Paging.tld" prefix="pagingTag"%>
<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags"%>
<head>
<title>Danh sách chapter</title>
<script type="text/javascript">
	$(function(){
		//lay thong bao notice
	  	var notice = $.getUrlVar('notice');
		if (notice != null || notice != "") {
			if(notice=="successfully"){
				$("#notice").html("Thành công");
				$("#notice").fadeOut(5000);
			}else if(notice=="error"){
				$("#notice").html("Dữ liệu truyền vào chưa chính xác.");
				$("#notice").fadeOut(5000);
			}
		}
		//end
	});
</script>
</head>
<body>
	<section class="database">
		<article>
			<input type="text" placeholder="tìm kiếm ..." class="kwSearch" value="${kwSearch}" />
			<br class="clr" />
			<br />
			Hiển thị : <select class="showRow" style="margin-right: 50px;">
				<option value="${sizePerPage}" selected="selected">${sizePerPage}</option>
				<option value="10">10</option>
				<option value="50">50</option>
				<option value="100">100</option>
				<option value="200">200</option>
			</select>
			Xem theo : <select class="sourceBy" style="margin-right: 50px;">
				<option value="1" <c:if test="${sourceBy=='blogtruyen'}">selected="selected"</c:if>>Blog truyện</option>
			</select>
			Sắp xếp theo : <select class="sortBy" style="margin-right: 50px;">
				<option value="id" <c:if test="${sortBy=='id'}">selected="selected"</c:if>>Id</option>
				<option value="chapterNumber" <c:if test="${sortBy=='chapterNumber'}">selected="selected"</c:if>>Số tập</option>
			</select>
			<select class="sort">
				<option value="asc" <c:if test="${sort=='asc'}">selected="selected"</c:if>>Tăng dần</option>
				<option value="desc" <c:if test="${sort=='desc'}">selected="selected"</c:if>>Giảm dần</option>
			</select>
			<script type="text/javascript">
					$(function() {
						$(".sourceBy").change(function() {
							var curPage = ${curPage};
							var sizePerPage = $(".showRow").val();
							var sort = $(".sort").val();
							var sortBy = $(".sortBy").val();
							var kwSearch = $(".kwSearch").val();
							var sourceBy = $(".sourceBy").val();
							$("body").load("<spring:url value='/quan-ly/chapterTruyenTinhCam/danh-sach-tat-ca-chapter-truyen.htm' />",{curPage:curPage,kwSearch:kwSearch,sizePerPage:sizePerPage,sortBy:sortBy,sort:sort,sourceBy:sourceBy});
						});
						$(".sortBy").change(function() {
							var curPage = ${curPage};
							var sizePerPage = $(".showRow").val();
							var sort = $(".sort").val();
							var sortBy = $(".sortBy").val();
							var kwSearch = $(".kwSearch").val();
							var sourceBy = $(".sourceBy").val();
							$("body").load("<spring:url value='/quan-ly/chapterTruyenTinhCam/danh-sach-tat-ca-chapter-truyen.htm' />",{curPage:curPage,kwSearch:kwSearch,sizePerPage:sizePerPage,sortBy:sortBy,sort:sort,sourceBy:sourceBy});
						});
						$(".kwSearch").change(function() {
							var curPage = ${curPage};
							var sizePerPage = $(".showRow").val();
							var sort = $(".sort").val();
							var sortBy = $(".sortBy").val();
							var kwSearch = $(this).val();
							var sourceBy = $(".sourceBy").val();
							$("body").load("<spring:url value='/quan-ly/chapterTruyenTinhCam/danh-sach-tat-ca-chapter-truyen.htm' />",{curPage:curPage,kwSearch:kwSearch,sizePerPage:sizePerPage,sortBy:sortBy,sort:sort,sourceBy:sourceBy});
						});
						$(".showRow").change(function() {
							var curPage = ${curPage};
							var sizePerPage = $(".showRow").val();
							var sort = $(".sort").val();
							var sortBy = $(".sortBy").val();
							var kwSearch = $(".kwSearch").val();
							var sourceBy = $(".sourceBy").val();
							$("body").load("<spring:url value='/quan-ly/chapterTruyenTinhCam/danh-sach-tat-ca-chapter-truyen.htm' />",{curPage:curPage,kwSearch:kwSearch,sizePerPage:sizePerPage,sortBy:sortBy,sort:sort,sourceBy:sourceBy});
						});
						$(".sort").change(function() {
							var curPage = ${curPage};
							var sizePerPage = $(".showRow").val();
							var sort = $(".sort").val();
							var sortBy = $(".sortBy").val();
							var kwSearch = $(".kwSearch").val();
							var sourceBy = $(".sourceBy").val();
							$("body").load("<spring:url value='/quan-ly/chapterTruyenTinhCam/danh-sach-tat-ca-chapter-truyen.htm' />",{curPage:curPage,kwSearch:kwSearch,sizePerPage:sizePerPage,sortBy:sortBy,sort:sort,sourceBy:sourceBy});
						});
						$('.capNhatChapterNumber').change(function(){
							$(this).parent().validationEngine();
							var id = $(this).attr('title');
							var chapterNumberChange = $(this).val();
							if(id != null && chapterNumberChange !=null){
								$.post('<spring:url value="/quan-ly/chapterTruyenTinhCam/doi-chapterNumber.htm" />', { id: id, chapterNumberChange: chapterNumberChange } );
							}else{
								alert("Giá trị không hợp lệ");
							}
						});
						$('.capNhatLinkSource').change(function(){
							$(this).parent().validationEngine();
							var id = $(this).attr('title');
							var linkSource = $(this).val();
							if(id != null && linkSource !=null){
								$.post('<spring:url value="/quan-ly/chapterTruyenTinhCam/doi-linkSource.htm" />', {id: id, linkSource: linkSource});
							}else{
								alert("Giá trị không hợp lệ");
							}
						});
					});
			</script>
			<c:choose>
				<c:when test="${lstChapterTruyen.size() > 0}">
						<h4 class="pInfo">Tổng số record : <font color="blue">${totalSize}</font></h4>
						<br class='clr' />
						<c:if test="${pInfo.totalPage > 1}">
							<section class="pInfo">
								<pagingTag:paging searchUrl="" curPageParam="curPage"
									searchValueParam="searchValue" pagingInf="${pInfo}"></pagingTag:paging>
							</section>
							<script type="text/javascript">
								$(function() {
									$(".bPage").click(function() {
										var curPage = $(this).val();
										var sizePerPage = $(".showRow").val();
										var sort = $(".sort").val();
										var sortBy = $(".sortBy").val();
										var kwSearch = $(".kwSearch").val();
										var sourceBy = $(".sourceBy").val();
										$("body").load("<spring:url value='/quan-ly/chapterTruyenTinhCam/danh-sach-tat-ca-chapter-truyen.htm' />",{curPage:curPage,kwSearch:kwSearch,sizePerPage:sizePerPage,sortBy:sortBy,sort:sort,sourceBy:sourceBy});
									});
								});
							</script>
						</c:if>
						<br class='clr' />
						<table class="tableCss">
							<thead>
								<tr>
									<th>Xóa</th>
									<th>ID</th>
									<th>Tên Chapter</th>
									<th>Tập</th>
									<th>Xữ lý</th>
								</tr>
							</thead>
							<tbody>
								<c:forEach items="${lstChapterTruyen}" var="item">
									<tr>
										<th><a href="<spring:url value='/quan-ly/chapterTruyenTinhCam/xoa-chapter-truyen.htm?id=${item.id}' />"><b class="red">-X-</b></a></th>
										<th>${item.id}</th>
										<th>${item.name}</th>
										<th><form><input type='text' title="${item.id}" class='capNhatChapterNumber validate[required,custom[numberFloat]]' value='<fmt:formatNumber type="number" maxIntegerDigits="4" value="${item.chapterNumber}" />' /></form></th>
										<th>
											<a href="<spring:url value='/quan-ly/chapterTruyenTinhCam/set-isDelete-chapter-truyen.htm?id=${item.id}' />">
												<c:choose>
													<c:when test="${item.chapterTruyenTinhCam.isDelete}">
														<b class="blue">Phục hồi</b>
													</c:when>
													<c:otherwise>
														<b class="red">X</b>
													</c:otherwise>
												</c:choose>
											</a>
											<a target="_blank" href="<spring:url value='/quan-ly/chapterTruyenTinhCam/cap-nhat-chapter-truyen.htm?id=${item.id}' />"><b class="green">+</b></a>
										</th>
									</tr>
								</c:forEach>
							</tbody>
						</table>
						<c:if test="${pInfo.totalPage > 1}">
							<section class="pInfo">
								<pagingTag:paging searchUrl="" curPageParam="curPage"
									searchValueParam="searchValue" pagingInf="${pInfo}"></pagingTag:paging>
							</section>
							<script type="text/javascript">
								$(function() {
									$(".bPage").click(function() {
										var curPage = $(this).val();
										var sizePerPage = $(".showRow").val();
										var sort = $(".sort").val();
										var sortBy = $(".sortBy").val();
										var kwSearch = $(".kwSearch").val();
										var sourceBy = $(".sourceBy").val();
										$("body").load("<spring:url value='/quan-ly/chapterTruyenTinhCam/danh-sach-tat-ca-chapter-truyen.htm' />",{curPage:curPage,kwSearch:kwSearch,sizePerPage:sizePerPage,sortBy:sortBy,sort:sort,sourceBy:sourceBy});
									});
								});
							</script>
						</c:if>
				</c:when>
				<c:otherwise>Chưa có dữ liệu...</c:otherwise>
			</c:choose>
		</article>
	</section>
</body>
